package view;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class RoomTable {
    private JFrame frame;
    private JTable table;

    public RoomTable(ResultSet rs) throws SQLException {
        frame = new JFrame("已入住房间");
        frame.setLayout(new BorderLayout());

        DefaultTableModel model = new DefaultTableModel();
        model.addColumn("房间号");

        while (rs.next()) {
            int rno = rs.getInt("Rno");
            model.addRow(new Object[]{rno});
        }

        table = new JTable(model);
        JScrollPane scrollPane = new JScrollPane(table);

        frame.add(scrollPane, BorderLayout.CENTER);

        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}